<?php
/** 
 * 送能量
 * Author:zhang
 *
 */
namespace Admin\Controller;

class EnergyController extends AdminController{
    //获取投诉列表
	public function index(){
	    $map['type'] = array('eq', '0');
        $list = $this->lists('energy_complaint', $map);
        foreach ($list as $key => $value) {
            $list[$key]['name'] = M('member')->where('uid='.$value['uid'])->getField('nickname');
            $list[$key]['enContent'] = M('energy')->where('id='.$value['eid'])->getField('content');
        }
        $this->assign('_list', $list);
        $this->meta_title = '送能量';
		$this->display();
	}
    //获取送能量的详情
	public function energyInfo(){
	    $id = I('get.id');
	    $result = M('energy')->where('id='.$id)->find();
        $result['imgPath'] = strstr($result['cover_ids'],",") ? implode(',', $result['cover_ids']):array($result['cover_ids']);
	    foreach($result['imgPath'] as $key =>$value) {
            $result['imgPath'][$key] = M('picture')->where('id='.$value)->getField('path');
        }
        $result['moviePath'] = M('movie')->where('id='.$result['movie_id'])->getField('savepath');
	    $this->assign('result', $result);
	    $this->display();
	}
	//处理投诉
	public function dispose(){
        $id = I('get.id');
        $type = I('get.type');
        if ($type == 2) {//不通过删除该能量并修改投诉状态
            $energyMode = M('energy');
            $energyMode -> startTrans();
            $resultEn = $energyMode->where('id='.$id)->delete();
            $resultCom = M('energy_complaint')->where('eid='.$id)->save(array('type'=>2));
            if ($resultEn && $resultCom) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {
            $result = M('energy_complaint')->where('eid='.$id)->save(array('type'=>1));
            if ($result) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        }
	}
}